package com.xnewtech.xplatform.swan.system.config;

import com.xnewtech.xplatform.swan.libs.config.properties.DruidProperties;
import com.xnewtech.xplatform.swan.system.core.dbs.DynamicDataSource;
import com.xnewtech.xplatform.swan.system.core.dbs.aop.MultiSourceExAop;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 多数据源druid配置
 *
 * @author xnew
 * @date 2020/8/24
 */
@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
@MapperScan(basePackages = {"com.xnewtech.xplatform.swan.system.modular.*.mapper"})
public class MultiDataSourceConfig {

    /**
     * druid配置
     */
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DruidProperties druidProperties() {
        return new DruidProperties();
    }

    /**
     * 多数据源的连接池
     *
     * @author xnew
     * @date 2020/8/25
     */
    @Bean
    public DynamicDataSource dataSource() {
        return new DynamicDataSource();
    }

    /**
     * 数据源切换的AOP
     *
     * @author xnew
     * @date 2020/8/25
     */
    @Bean
    public MultiSourceExAop multiSourceExAop() {
        return new MultiSourceExAop();
    }

}
